<template>
    <el-table :data="tableData" cell-class-name="pp"
              header-cell-class-name="pp" stripe>
        <el-table-column label="#" type="index"/>
        <el-table-column label="房区编号" prop="areaId"/>
        <el-table-column label="房区名称" prop="areaName">
            <template #default="scope">
                <span>{{ `${scope.row.areaName}区` }}</span>
            </template>
        </el-table-column>
        <el-table-column label="启用状态" prop="status">
            <template #default="scope">
                <el-switch v-model="scope.row.status" @change="changeStatus(scope.row)"/>
            </template>
        </el-table-column>
        <el-table-column label="启用时间" prop="updateTime">
            <template #default="scope">
                {{ dealDateTime(scope.row.updateTime) }}
            </template>
        </el-table-column>
    </el-table>
</template>

<script lang="ts" setup>
import { AreaService } from '@/api'
import { ref } from 'vue'
import { Area } from '@/ts/type'
import { dealDateTime } from '@/utils/commonUtils'
import { Notification } from '@/plugins/element'

const tableData = ref<Area[]>([])
const getList = async () => {
  await AreaService.getList().then(res => {
    console.log(res.data)
    const { data } = res
    tableData.value = data
  })
}

const changeStatus = async (row: Area) => {
  await AreaService.updateList(row).then(async res => {
    await getList()
    const { message } = res
    Notification.success(message)
  })
}
getList()
</script>

<style lang="scss" scoped>
:deep(.pp ) {
  text-align: center;
}
</style>